package com.bqtv.sport.ui.home.fragment

import android.os.Bundle
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import androidx.viewbinding.ViewBinding
import com.bqtv.sport.adapter.HomeHotAdapter
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.app.AppFragment
import com.bqtv.sport.commen.widget.GridItemDecoration
import com.bqtv.sport.databinding.FragmentHomeNormalBinding
import com.bqtv.sport.ui.home.LiveDetailActivity


class HomeNormalFragment :
    AppFragment<FragmentHomeNormalBinding, AppActivity<ViewBinding>>() {
    private lateinit var hotAdapter: HomeHotAdapter

    companion object {
        private const val INTENT_KEY_TYPE = "type"

        fun newInstance(type: Int): HomeNormalFragment {
            val fragment = HomeNormalFragment()
            val bundle = Bundle()
            bundle.putInt(INTENT_KEY_TYPE, type)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun getViewBinding() = FragmentHomeNormalBinding.inflate(layoutInflater)

    override fun initView() {

        binding.recyclerHot.layoutManager =
            StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
        binding.recyclerHot.addItemDecoration(
            GridItemDecoration(
                getContext(), 2,
                GridItemDecoration.LineDrawMode.HORIZONTAL, 10, 15
            )
        )

        hotAdapter = HomeHotAdapter()
        binding.recyclerHot.adapter = hotAdapter
    }

    override fun initData() {

        val list: MutableList<String> = ArrayList()
        list.add("1")
        list.add("2")
        list.add("3")
        list.add("4")

        hotAdapter.submitList(list)

        initListener()
    }
    private fun initListener() {
        hotAdapter.setOnItemClickListener({ adapter, view, position ->
            LiveDetailActivity.start(getAttachActivity()!!, 1);
        })
    }
}

